﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Threading;

namespace WebServer
{
	/// <summary>
	/// Event Handler for the CoreMessage Event
	/// </summary>
	public delegate void CoreMessageHandler(CoreMessageEventArgs e);
	/// <summary>
	/// Event Handler for the CoreInitialized Event
	/// </summary>
	public delegate void CoreInitializedEventHandler();
	/// <summary>
	/// Event Handler for the CoreClosed Event
	/// </summary>
	public delegate void CoreClosedEventHandler();

	/// <summary>
	/// Event Handler for the HTTPRequest Event
	/// </summary>
	public delegate void HTTPRequestEventHandler(HTTPRequestEventArgs e);
	/// <summary>
	/// Event Handler for the HTTPRequestFail Event
	/// </summary>
	public delegate void HTTPRequestFailEventHandler(HTTPRequestFailEventArgs e);
	/// <summary>
	/// Event Handler for the HTTPRequestSuccess Event
	/// </summary>
	public delegate void HTTPRequestSuccessEventHandler(HTTPRequestSuccessEventArgs e);

	/// <summary>
	/// Event Handler for the PageRetrieved Event.
	/// </summary>
	public delegate void WebObjectRetrievedEventHandler(WebObjectRetrievedEventArgs e);

	/*
	/// <summary>
	/// Event Handler for the CMDHandled Event.
	/// </summary>
	public delegate void CMDEventHandler(CMDEventArgs e);
	*/

	public delegate void CoreModuleStartedEventHandler();

	/// <summary>
	/// List of request status used to describe the current status of a request operation.
	/// </summary>
	public enum RequestStatus
	{
		/// <summary>
		/// Used whenever a web request fails.
		/// </summary>
		Failed,
		/// <summary>
		/// Used whenever a web request succeeds.
		/// </summary>
		Successful,
		/// <summary>
		/// Used whenever a web request is processing.
		/// </summary>
		Processing
	}

	/// <summary>
	/// Describes the type of message.
	/// </summary>
	public enum CoreMessageAction
	{
		/// <summary>
		/// Message is Error
		/// </summary>
		Error,
		/// <summary>
		/// Message is Input
		/// </summary>
		Input,
		/// <summary>
		/// Message is Output
		/// </summary>
		Output
	}

	/// <summary>
	/// Provides the means to handle various Events invoked by the WebServer Core
	/// </summary>
	public static class Events
	{


		/// <summary>
		/// Fired when the WebServer Core receives an input, output or error message
		/// </summary>
		public static event CoreMessageHandler CoreMessage;
		/// <summary>
		/// Fired when the WebServer Core is successfully initialized
		/// </summary>
		public static event CoreInitializedEventHandler CoreInitialized;
		/// <summary>
		/// Fired when the WebServer Core is closed
		/// </summary>
		public static event CoreClosedEventHandler CoreClosed;
		/// <summary>
		/// Fired whenever a web request is received
		/// </summary>
		public static event HTTPRequestEventHandler HTTPRequest;
		/// <summary>
		/// Fired whenever a web request fails
		/// </summary>
		public static event HTTPRequestFailEventHandler HTTPRequestFail;
		/// <summary>
		/// Fired whenever a web request succeeds
		/// </summary>
		public static event HTTPRequestSuccessEventHandler HTTPRequestSuccess;
		/// <summary>
		/// Fired whenever a web-webObj is retrieved from the virtual or static registries, including the internal 'error' and 'blank' pages
		/// </summary>
		public static event WebObjectRetrievedEventHandler WebObjectRetrieved;
		/*
		/// <summary>
		/// Not yet implimented. Fired whenever a command request is handled
		/// </summary>
		public static event CMDEventHandler CMDHandled;
		*/

		/// <summary>
		/// Invokes the CoreMessage event
		/// </summary>
		public static void InvokeCoreMessage(CoreMessageEventArgs e)
		{
			if (CoreMessage != null)
				CoreMessage.Invoke(e);
		}

		/// <summary>
		/// Invokes the CoreInitialized event
		/// </summary>
		public static void InvokeCoreInitialized()
		{
			if (CoreInitialized != null)
				CoreInitialized.Invoke();
		}

		/// <summary>
		/// Invokes the CoreClosed event
		/// </summary>
		public static void InvokeCoreClosed()
		{
			if (CoreClosed != null)
				CoreClosed.Invoke();
		}

		/// <summary>
		/// Invokes the HTTPRequest event
		/// </summary>
		public static void InvokeHTTPRequest(HTTPRequestEventArgs e)
		{
			if (HTTPRequest != null)
				HTTPRequest.Invoke(e);
		}

		/// <summary>
		/// Invokes the HTTPRequestFail event
		/// </summary>
		public static void InvokeHTTPRequestFail(HTTPRequestFailEventArgs e)
		{
			if (HTTPRequestFail != null)
				HTTPRequestFail.Invoke(e);
		}

		/// <summary>
		/// Invokes the HTTPRequestSuccess event
		/// </summary>
		public static void InvokeHTTPRequestSuccess(HTTPRequestSuccessEventArgs e)
		{
			if (HTTPRequestSuccess != null)
				HTTPRequestSuccess.Invoke(e);
		}

		/// <summary>
		/// Invokes the PageRetrieved event
		/// </summary>
		public static void InvokeWebObjectRetrieved(WebObjectRetrievedEventArgs e)
		{
			if (WebObjectRetrieved != null)
				WebObjectRetrieved.Invoke(e);
		}

		/*
		/// <summary>
		/// Invokes the CMDHandled event
		/// </summary>
		public static void InvokeCMDHandled(CMDEventArgs e)
		{
			if (CMDHandled != null)
				CMDHandled.Invoke(e);
		}
		*/
	}
}
